 @echo off
chcp 65001 >nul
echo ========================================
echo    P2P 桌面共享项目打包工具
echo ========================================
echo.

echo 正在创建项目包...
if exist "p2pdesktop-package" rmdir /s /q "p2pdesktop-package"
mkdir "p2pdesktop-package"

echo 复制项目文件...
xcopy "server" "p2pdesktop-package\server\" /E /I /Y
xcopy "public" "p2pdesktop-package\public\" /E /I /Y
copy "package.json" "p2pdesktop-package\"
copy "start-server.bat" "p2pdesktop-package\"
copy "stop-server.bat" "p2pdesktop-package\"
copy "README.md" "p2pdesktop-package\"

echo 创建安装脚本...
echo @echo off > "p2pdesktop-package\install.bat"
echo chcp 65001 ^>nul >> "p2pdesktop-package\install.bat"
echo echo 正在安装 P2P 桌面共享应用... >> "p2pdesktop-package\install.bat"
echo echo. >> "p2pdesktop-package\install.bat"
echo echo 检查 Node.js... >> "p2pdesktop-package\install.bat"
echo node --version ^>nul 2^>^&1 >> "p2pdesktop-package\install.bat"
echo if errorlevel 1 ^( >> "p2pdesktop-package\install.bat"
echo     echo 错误: 未找到 Node.js >> "p2pdesktop-package\install.bat"
echo     echo 请先安装 Node.js: https://nodejs.org/ >> "p2pdesktop-package\install.bat"
echo     pause >> "p2pdesktop-package\install.bat"
echo     exit /b 1 >> "p2pdesktop-package\install.bat"
echo ^) >> "p2pdesktop-package\install.bat"
echo echo Node.js 已安装 >> "p2pdesktop-package\install.bat"
echo echo. >> "p2pdesktop-package\install.bat"
echo echo 安装依赖包... >> "p2pdesktop-package\install.bat"
echo npm install >> "p2pdesktop-package\install.bat"
echo echo. >> "p2pdesktop-package\install.bat"
echo echo 安装完成！ >> "p2pdesktop-package\install.bat"
echo echo 运行 start-server.bat 启动应用 >> "p2pdesktop-package\install.bat"
echo pause >> "p2pdesktop-package\install.bat"

echo 创建使用说明...
echo # P2P 桌面共享应用 - 使用说明 > "p2pdesktop-package\使用说明.txt"
echo. >> "p2pdesktop-package\使用说明.txt"
echo ## 安装步骤 >> "p2pdesktop-package\使用说明.txt"
echo 1. 确保已安装 Node.js (https://nodejs.org/) >> "p2pdesktop-package\使用说明.txt"
echo 2. 双击 install.bat 安装依赖 >> "p2pdesktop-package\使用说明.txt"
echo 3. 双击 start-server.bat 启动应用 >> "p2pdesktop-package\使用说明.txt"
echo 4. 在浏览器中访问 http://localhost:3001 >> "p2pdesktop-package\使用说明.txt"
echo. >> "p2pdesktop-package\使用说明.txt"
echo ## 停止应用 >> "p2pdesktop-package\使用说明.txt"
echo 双击 stop-server.bat 停止服务器 >> "p2pdesktop-package\使用说明.txt"
echo. >> "p2pdesktop-package\使用说明.txt"
echo ## 系统要求 >> "p2pdesktop-package\使用说明.txt"
echo - Windows 7 或更高版本 >> "p2pdesktop-package\使用说明.txt"
echo - Node.js 14.0 或更高版本 >> "p2pdesktop-package\使用说明.txt"
echo - 现代浏览器 (Chrome, Firefox, Edge) >> "p2pdesktop-package\使用说明.txt"

echo 创建压缩包...
powershell -command "Compress-Archive -Path 'p2pdesktop-package\*' -DestinationPath 'p2pdesktop-v1.0.zip' -Force"

echo.
echo ✅ 打包完成！
echo 📦 项目包: p2pdesktop-v1.0.zip
echo 📁 解压目录: p2pdesktop-package
echo.
echo 将 p2pdesktop-v1.0.zip 复制到其他PC即可使用
echo.
pause